<template>
  <div id="container">
    <div id="head">
      <div class="title">
        环保公众监督系统
      </div>
    </div>

    <div id="body">
      <div class="loginwin">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <h1 class="align-center">登录</h1>
            </div>
          </template>
          <div class="loginform">
            <el-form :model="ruleForm" ref="ruleFormRef" class="demo-ruleForm" :size="formSize" status-icon :rules="rules">
              <el-form-item prop="loginName">
                <el-input v-model="ruleForm.loginName" size="large" placeholder="请输入用户名或手机号" :prefix-icon="Avatar" class="input-animated" />
              </el-form-item>
              <el-form-item prop="checkPass">
                <el-input v-model="ruleForm.password" size="large" placeholder="请输入密码" :prefix-icon="Lock" type="password" show-password class="input-animated" />
              </el-form-item>
              <el-form-item>
                <div class="btn-container">
                  <el-button type="primary" @click="submitForm(ruleFormRef)" :icon="Promotion" class="button-animated">
                    立即登录
                  </el-button>
                  <el-button type="text" @click="register" class="button-animated">注册</el-button>
                </div>
              </el-form-item>
            </el-form>
          </div>
        </el-card>
      </div>
    </div>

    <div class="footer">
      <div class="bubbles">
        <div v-for="i in 120" :key="i" class="bubble" :style="getBubbleStyle()"></div>
      </div>
      <div class="content">
        <div>
          <div>
            <b>关于东软</b>
            <a href="https://www.neuedu.com/page/Company-Profile">公司简介</a>
            <a href="https://www.neuedu.com/channel/MT.html">管理团队</a>
            <a href="https://www.neuedu.com/page/Business-philosophy">文化理念</a>
            <a href="https://www.neuedu.com/channel/history.html">发展历程</a>
          </div>
          <div>
            <b>绿色和平</b>
            <a href="https://www.greenpeace.org.cn/climate-and-energy/">气候与能源</a>
            <a href="https://www.greenpeace.org.cn/biodiversity/">保护生物多样性</a>
            <a href="https://www.greenpeace.org.cn/live-sustainably/">可持续生活</a>
          </div>
        </div>
        <div>
          <div>
            <b>投资者</b>
            <a href="#">公司治理</a>
            <a href="#">股本变化</a>
            <a href="#">公司公告</a>
            <a href="#">财务报告</a>
          </div>
          <div>
            <b>联系我们</b>
            <a href="#">业务咨询</a>
            <a href="#">售后咨询</a>
            <a href="#">致电咨询</a>
            <a href="#">其他咨询</a>
          </div>
        </div>
        <div class="footer-brand">
          <img src="@/assets/img/footers.png" alt="logo" class="footer-image" />
          <p>©2024 基因重组</p>
        </div>
      </div>
      <svg style="position:fixed; top:30vh">
        <defs>
          <filter id="blob">
            <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur"/>
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="blob"/>
          </filter>
        </defs>
      </svg>
    </div>
  </div>
</template>


<script setup>
import { Avatar, Lock, Promotion } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus';
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router';
import $axios from '../components/utils/axios'
const router = useRouter()

const formSize = ref('default')

const ruleFormRef = ref()
const ruleForm = ref({
  // loginName: '13111111111',
  // password: '33333'
})

const validatePass2 = (rule, value, callback) => {
  if (!ruleForm.value.password || ruleForm.value.password.length == 0)
    callback(new Error('请输入密码'))
  if (ruleForm.value.password === '')
    callback(new Error('请输入密码'))
  else callback()
}

const rules = reactive({
  loginName: [
    {
      required: true,
      message: '请输入用户名或手机号',
      trigger: 'blur'
    },
    {
      min: 4,
      max: 11,
      message: '4-11个字符',
      trigger: 'blur'
    }
  ],
  password: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'blur'
    },
    {
      min: 5,
      max: 10,
      message: '5-10个字符',
      trigger: 'blur'
    }
  ],
  checkPass: [
    { validator: validatePass2, trigger: 'blur' }
  ]
})

const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      const path = '/user/login'
      const { data: res } = await $axios.post(path, ruleForm.value, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
          Authorization: sessionStorage.getItem('token')
        }
      })
      if (res.code === 200) {
        let user = res.result
        let jsonstr = JSON.stringify(user)
        sessionStorage.setItem('user', jsonstr)
        sessionStorage.setItem('id', user.id + '')
        localStorage.setItem('id', user.id + '')
        sessionStorage.setItem('token', user.token)
        sessionStorage.setItem('roleId', user.roleId + '')
        sessionStorage.setItem('avatar', user.avatar)

        sessionStorage.setItem('isNotified', false)
        if (user.roleId === 3) {
          router.push('/IndividualCenter')
        }
        else if (user.roleId === 2) {
          router.push('/IndividualCenter')
        }
        else if (user.roleId === 1) {
          router.push('/ChinaCharts')
        }
      }
      else if (res.code === 100) {
        ElMessage.error("密码错误！")
      }
    } else {
      console.log('error submit!', fields)
    }
  })
}

const register = () => {
  router.push('/register')
}

const getBubbleStyle = () => {
  return {
    '--size': `${2 + Math.random() * 4}rem`,
    '--distance': `${6 + Math.random() * 4}rem`,
    '--position': `${-5 + Math.random() * 100}%`,
    '--time': `${2 + Math.random() * 2}s`,
    '--delay': `${-1 * (2 + Math.random() * 2)}s`
  }
}
</script>

<style lang="scss" scoped>
@import url('https://fonts.googleapis.com/css2?family=Jost:wght@500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@400;600&display=swap');
#container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
  background: url('@/assets/img/bg.jpeg') no-repeat center center fixed; /* 修改为背景图片 */
  background-size: cover; /* 让背景图片覆盖整个容器 */
  backdrop-filter: blur(5px); /* 添加模糊效果 */
  #head {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;

    .title {
      font-size: 40px;
      color: #ffffff;
      font-family: 'Jost', sans-serif;
    }
  }

  #body {
    position: relative;
    margin-top: -50px;
    height: 100%;
    width: 100%;
   
    .loginwin {
      width: 400px;
      height: 300px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      border-radius: 20px; /* 增加圆角 */
      .box-card {
        width: 400px;
        height: 300px;
        margin: 0 auto;
        float: inline-start;
        text-align: center;
        border-radius: 20px; /* 增加圆角 */
        background: rgba(240, 248, 255, 0.85); /* 透明度 */
        box-shadow: 0 8px 16px rgba(34, 199, 122, 0.2); /* 添加阴影 */
        align-items: center;

        .card-header {
          display: flex;
          margin-bottom: -20px;
          
          .align-center {
            width: 100%;
            font-size: 25px;
            text-align: center;
            color: #1c70de;
            font-family: 'Raleway', sans-serif; /* 更改字体 */
          }
        }

        .loginform {
          padding: 30px;
          .input-animated {
            transition: all 0.3s ease;
            border-radius: 10px;
          }
          .input-animated:focus-within {
            border-color: #1c70de;
            box-shadow: 0 0 10px rgba(28, 112, 222, 0.5);
          }
          .btn-container {
            display: flex;
            justify-content: center;

            .button-animated {
              transition: all 0.3s ease;
              border-radius: 10px;
              padding: 10px 20px;
              margin: 0 10px;
              background-color: #1c70de;
              color: #fff;
              font-family: 'Raleway', sans-serif;
            }

            .button-animated:hover {
              background-color: #145a9d;
              box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
            }
          }


        }
      }
    }
  }

  .footer {
    z-index: 1;
    --footer-background: linear-gradient(to right,#94ceee, #7cc6d5); /* 半透明水色渐变 */
    // --footer-background: linear-gradient(to right, #bdc3c7, #2c3e50); /* 渐变色 */
    // --footer-background: rgba(255, 253, 253, 0.611); /* 透明度 */
    display: grid;
    position: relative;
    grid-area: footer;
    // height: 20%;
    // min-height: 3rem;

    .bubbles {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 1rem;
      background: var(--footer-background);
      filter: url("#blob");
      .bubble {
        position: absolute;
        left: var(--position, 50%);
        background: var(--footer-background);
        border-radius: 100%;
        animation: bubble-size var(--time, 3s) ease-in infinite var(--delay, 0s),
                   bubble-move var(--time, 3s) ease-in infinite var(--delay, 0s);
        transform: translate(-50%, 100%);
      }
    }

    .content {
      z-index: 2;
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      grid-gap: 1rem;
      padding: 1rem;
      font-size: 14px;
      background: var(--footer-background);
      a, p {
        color: #F5F7FA; 
        text-decoration: none;
        letter-spacing: 0.1rem;
      }
      b {
        color: white;
        letter-spacing: 0.1rem;
      }
      p {
        margin: 0;
        font-size: 14px;
      }
      > div {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin: auto;
        > div {
          margin: 0.25rem 0;
          > * {
            margin-right: .5rem;
          }
        }
        .image {
          align-self: center;
          width: 4rem;
          height: 4rem;
          margin: 0.25rem 0;
          background-size: cover;
          background-position: center;
        }
      }
      .footer-image {
        width: 80px;
        height: auto;
        display: block;
        margin: auto;
      }
    }
    .footer-brand {
      display: flex;
      flex-direction: column;
      align-items: center;
      p {
        margin-top: 0.5rem;
      }
    }
  }
}

@keyframes bubble-size {
  0%, 75% {
    width: var(--size, 2rem);
    height: var(--size, 2rem);
  }
  100% {
    width: 0rem;
    height: 0rem;
  }
}
@keyframes bubble-move {
  0% {
    bottom: -1rem;
  }
  100% {
    bottom: var(--distance, 8rem);
  }
}

</style>

